package wrappers;

import views.ViewElement;
import java.util.List;
import java.util.LinkedList;
import views.CurrencyElement;
import views.DateElement;
import web.Formatter;
import views.TextElement;

/**
 *
 * @author Alejandro
 */
public class EmployeeWrap extends AbstractWrap {

    public static int IDR = 1;
    private int id;
    private String name;
    private String surname;
    private String job;
    private int manager;
    private String hiredate;
    private int salary;
    private int department;
    private ViewElement viewManager;
    private ViewElement viewDepartment;

    public EmployeeWrap() {
        name = "";
        surname = "";
        job = "";
        hiredate = "";
    }

    public EmployeeWrap(int id, String name, String surname, String job, int manager, String hiredate, int salary, int department) {
        this.id = id;
        this.name = name;
        this.surname = surname;
        this.job = job;
        this.manager = manager;
        this.hiredate = hiredate;
        this.salary = salary;
        this.department = department;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getSurname() {
        return surname;
    }

    public String getJob() {
        return job;
    }

    public int getManager() {
        return manager;
    }

    public String getDate() {
        return hiredate;
    }

    public int getSalary() {
        return salary;
    }

    public int getDepartment() {
        return department;
    }

    public void setViewManager(ViewElement _manager) {
        viewManager = _manager;
    }

    public void setViewDepartment(ViewElement _department) {
        viewDepartment = _department;
    }

    public ViewElement getViewId() {
        return new TextElement("id", Integer.toString(id));
    }

    public ViewElement getViewName() {
        return new TextElement("name", name);
    }

    public ViewElement getViewSurname() {
        return new TextElement("surname", surname);
    }

    public ViewElement getViewJob() {
        return new TextElement("job", job);
    }

    public ViewElement getViewDate() {
        return new DateElement("date", hiredate);
    }

    public ViewElement getViewSalary() {
        return new CurrencyElement("salary", Integer.toString(salary));
    }

    public ViewElement getViewManager() {
        return viewManager;
    }

    public ViewElement getViewDepartment() {
        return viewDepartment;
    }

    @Override
    public int compareTo(Object o) {
        int result = 0;
        EmployeeWrap ew = (EmployeeWrap) o;
        switch (ss.getParam()) {
            case 0:
                result = (ss.isAscending()) ? (id - ew.id) : (ew.id - id);
                break;
            case 1:
                result = (ss.isAscending()) ? (name.compareTo(ew.name)) : (ew.name.compareTo(name));
                break;
            case 2:
                result = (ss.isAscending()) ? (surname.compareTo(ew.surname)) : (ew.surname.compareTo(surname));
                break;
            case 3:
                result = (ss.isAscending()) ? (job.compareTo(ew.job)) : (ew.job.compareTo(job));
                break;
            case 4:
                result = (ss.isAscending()) ? (this.getViewManager().toString().compareTo(ew.getViewManager().toString())) : (ew.getViewManager().toString().compareTo(this.getViewManager().toString()));
                break;
            case 5:
                result = (ss.isAscending()) ? (hiredate.compareTo(ew.hiredate)) : (ew.hiredate.compareTo(hiredate));
                break;
            case 6:
                result = (ss.isAscending()) ? (salary - ew.salary) : (ew.salary - salary);
                break;
            case 7:
                result = (ss.isAscending()) ? (this.getViewDepartment().toString().compareTo(ew.getViewDepartment().toString())) : (ew.getViewDepartment().toString().compareTo(this.getViewDepartment().toString()));
                break;
        }
        return result;
    }

    @Override
    public List<String> getHeaders() {
        List<String> headers = new LinkedList<String>();
        headers.add(getViewId().getHeader());
        headers.add(getViewName().getHeader());
        headers.add(getViewSurname().getHeader());
        headers.add(getViewJob().getHeader());
        headers.add(getViewManager().getHeader());
        headers.add(getViewDate().getHeader());
        headers.add(getViewSalary().getHeader());
        headers.add(getViewDepartment().getHeader());
        return headers;
    }

    @Override
    public List<ViewElement> getCells() {
        List<ViewElement> cells = new LinkedList<ViewElement>();
        cells.add(getViewId());
        cells.add(getViewName());
        cells.add(getViewSurname());
        cells.add(getViewJob());
        cells.add(getViewManager());
        cells.add(getViewDate());
        cells.add(getViewSalary());
        cells.add(getViewDepartment());
        return cells;
    }

    @Override
    public String getPrimaryKey() {
        return Integer.toString(id);
    }
}
